package cn.easybuy.web.backend;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.alibaba.fastjson.JSON;

import cn.easybuy.entity.Product;
import cn.easybuy.service.ProductService;
import cn.easybuy.service.impl.ProductServiceImpl;
import cn.easybuy.util.Page;

public class ProductServlet1 extends HttpServlet{

	@Override
	protected void service(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		String opr =request.getParameter("opr");
		PrintWriter out =response.getWriter();
		ProductService prService=new ProductServiceImpl();
		Page page =new Page();
		if (opr.equals("show")) {
			String currNo=request.getParameter("currNo");
			if (currNo==null||currNo=="") {
				currNo="1";
			}
			page.setCurrentPageNumber(Integer.parseInt(currNo));
			page.setPageSize(10);
			int totalCount=prService.getTotalCount();
			page.setTotalCount(totalCount);
			
			List<Product> list=prService.getProductCategories(Integer.parseInt(currNo), page.getPageSize());
			page.setProductList(list);
			String listJson=JSON.toJSONString(page);
			out.print(listJson);
		}
		out.flush();
		out.close();
	}

}
